package cc.telecomdigital.tdstock.activity.groups.more;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.StringUtils;
import cc.telecomdigital.tdstock.Framework.ActivityGroup_Framework;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Http.H_CODE;
import cc.telecomdigital.tdstock.Http.Services.HttpAppInfo;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.H_UserClient_HttpRequest_Result;
import cc.telecomdigital.tdstock.Services.LS_SubscriptionItem;
import cc.telecomdigital.tdstock.Services.LS_UserClient.CONNECTION_STATUS;
import cc.telecomdigital.tdstock.Services.LS_UserClient.ILS_UserClient_Response;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BMPBaseActivity;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;
import cc.telecomdigital.tdstock.activity.groups.StockGroup;
import cc.telecomdigital.tdstock.activity.groups.stock.BMPCurrentStockInfoActivity;
import cc.telecomdigital.tdstock.activity.groups.stock.CurrentStockInfoActivity;
import cc.telecomdigital.tdstock.model.Top20StockInfo;
import cc.telecomdigital.tdstock.utils.Top20Stock;

import com.lightstreamer.ls_client.UpdateInfo;

/**
 * BMP Top 20
 * 
 * @author ouyangzhihui
 */
public class BMPTop20Activity extends BMPBaseActivity implements ILS_UserClient_Response
{
	protected static final String	TAG				= "BMPTop20Activity";

	private List<Top20Stock>		_top20List		= new ArrayList<Top20Stock>();

	private static final String		VOLUME			= "Volume";
	private static final String		TURNOVER		= "Turnover";
	private ViewGroup				_listViewTitle;
	private TextView				_listViewColumn_4;
	private TextView				_listViewColumn_5;
	private TextView				_topBarTitle;

	private boolean					isNet			= true;
	private String					headerTitle 	= null;
	private String					typeName_header	= "STOCKLIST_";				// 
	private String					tagName			= null;
	
	private ListView				_listView;
	private Top20Adapter			_adapter;
	
	protected boolean				_isInBackground = false;

	@Override
	public void onCreate(final Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		TDStockLog.d(TAG, TAG + " onCreate");

		setContentView(R.layout.bmp_top20);

		_listViewTitle = (ViewGroup) findViewById(R.id.transparent_panel);
		
		_topBarTitle = (TextView) findViewById(R.id.top_bar_title);
		_listViewColumn_4 = (TextView) findViewById(R.id.monitor_column_4);
		_listViewColumn_5 = (TextView) findViewById(R.id.monitor_column_5);

		_listView = (ListView) findViewById(R.id.top20_list);

		_adapter = new Top20Adapter(this, _top20List);
		// Adjust Size when display changes?
		_listView.setAdapter(_adapter);

		_listView.setOnItemClickListener(new OnItemClickListener()
		{
			@Override
			public void onItemClick(AdapterView<?> parent, View iView, int iIndex, long iArgs)
			{
				int objId = parent.getId();
				switch (objId)
				{
					case R.id.top20_list:
						if (iIndex != -1)
						{
							TDStockLog.d(TAG, "item click");
							forwardToDestActivity(iIndex);
						}
						break;
				}
			}
		});

		Button _toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		Button _toolBtnTop20stock = (Button) findViewById(R.id.top20stock);
		_toolBtnReturn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "close current activity and forwarding to the previous");

				((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, "");
				Intent intent = new Intent(getApplicationContext(), MoreActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchTabHostActivity(4, MoreGroup.GetActivityGroupHostControl(), MoreActivity.class, intent);
			}
		});
		_toolBtnTop20stock.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(getApplicationContext(), Top20StockListActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchTabHostActivity(4, MoreGroup.GetActivityGroupHostControl(), Top20StockListActivity.class, intent);
			}
		});
	}

	private void resetTitle()
	{
		_listViewTitle.setVisibility(((ITDLApplication) getApplicationContext()).getDataMode() == CommonDefn.DataMode.Delay ? View.VISIBLE : View.GONE);
	}
	
	private void resetHeaderTitle()
	{
		// restore the column name of list view;
		_topBarTitle.setText(headerTitle);
		
		if (tagName.indexOf(VOLUME) >= 0 || tagName.indexOf(TURNOVER) >= 0)
		{
			_listViewColumn_4.setText(R.string.monitor_column_volume);
			_listViewColumn_5.setText(R.string.monitor_column_turnover);
			isNet = false;
		}
		else
		{
			_listViewColumn_4.setText(R.string.net);
			_listViewColumn_5.setText(R.string.net_percentage);
			isNet = true;
		}
	}

	private class Top20ItemViewHolder
	{
		public TextView	itemCode;
		public TextView	itemName;
		public TextView	itemValue;
		public TextView	itemNet;
		public TextView	itemNetPercentage;
	}

	/*
	 * adapter
	 */
	private class Top20Adapter extends BaseAdapter
	{
		private LayoutInflater		mInflater;
		private List<Top20Stock>	list;

		public Top20Adapter(Context context, List<Top20Stock> list)
		{
			mInflater = LayoutInflater.from(context);
			this.list = list;
		}

		@Override
		public int getCount()
		{
			return list.size();
		}

		@Override
		public Object getItem(int position)
		{
			return list.get(position);
		}

		@Override
		public long getItemId(int position)
		{
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent)
		{
			Top20ItemViewHolder holder = null;
			if (convertView == null)
			{
				convertView = mInflater.inflate(R.layout.bmp_top20_list_item, null);
				holder = new Top20ItemViewHolder();
				holder.itemCode = (TextView) convertView.findViewById(R.id.monitor_item_code);
				holder.itemName = (TextView) convertView.findViewById(R.id.monitor_item_name);
				holder.itemValue = (TextView) convertView.findViewById(R.id.monitor_item_value);
				holder.itemNet = (TextView) convertView.findViewById(R.id.monitor_item_net);
				holder.itemNetPercentage = (TextView) convertView.findViewById(R.id.monitor_item_netpercentage);

				convertView.setTag(holder);
			}
			else
			{
				holder = (Top20ItemViewHolder) convertView.getTag();
			}

			Top20Stock item = list.get(position);
			if (item != null)
			{
				holder.itemCode.setText(item.getStockCode());
				holder.itemName.setText(item.getSchiName());
				holder.itemValue.setText(item.getNominal());
				if (isNet)
				{
					if(item.getNet() == null) item.setNet("--");
					holder.itemNet.setText(item.getNet());
					holder.itemNetPercentage.setText(item.getNetPercentage());

					holder.itemNet.setTextColor(item.getNet().startsWith("-") ? Color.RED : CommonDefn.FOREST_GREEN);
					holder.itemNetPercentage.setTextColor(item.getNet().startsWith("-") ? Color.RED : CommonDefn.FOREST_GREEN);
				}
				else
				{
					holder.itemNet.setText(item.getShareTraded());
					holder.itemNetPercentage.setText(item.getTurnover());

					holder.itemNet.setTextColor(CommonDefn.FOREST_GREEN);
					holder.itemNetPercentage.setTextColor(CommonDefn.FOREST_GREEN);
				}
			}
			convertView.setId(position);
			return convertView;
		}
	}

//	private class Top20LoadDataAsyncTask extends BaseAsyncTask
//	{
//		public Top20LoadDataAsyncTask(Context context)
//		{
//			super(context);
//		}
//
//		@Override
//		protected void onPreExecute()
//		{
//			super.onPreExecute();
//			if(_top20List.size() > 0)
//			{
//				_top20List.clear();
//				_adapter.notifyDataSetChanged();
//			}
//		}
//
//		@Override
//		protected Void doInBackground(String... params)
//		{
//			if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
//			{
//				String name = tagName;
//				
//				String accountNumber = ((ITDLApplication) getApplicationContext()).getSessionAccount();
//				String sessionKey = ((ITDLApplication) getApplicationContext()).getSessionToken();
//				
//				TDStockLog.d(TAG, "SessionKey: "+accountNumber+","+sessionKey);
//				
//				List<Top20Stock> list = HttpDataBaseUtils.getDataByTop20Stock(name, isNet, accountNumber, sessionKey);
//	
//				for (Top20Stock stock : list)
//				{
//					try
//					{
//						// 現價
//						String nominal = stock.getNominal();
//						if (nominal.indexOf(".") >= 5)
//						{
//							nominal = StringUtils.roundDownInteger(nominal);
//						}
//						else
//						{
//							nominal = StringUtils.roundDownFormatToFiveCharsRule(nominal);
//						}
//						stock.setNominal(nominal);
//	
//						// 升跌$,升跌%,成交量,成交額
//						if (name.contains(Top20Stock.TypeName_NetGainers)) // 升
//						{
//							stock.setNet(StringUtils.formatNumberByNet(stock.getNet()));
//							stock.setNetPercentage(StringUtils.formatNumberByNetPerectage(stock.getNetPercentage(), 5));
//						}
//						else if (name.contains(Top20Stock.TypeName_NetLosers)) // 跌
//						{
//							stock.setNet(StringUtils.formatNumberByNet(stock.getNet()));
//							stock.setNetPercentage(StringUtils.formatNumberByNetPerectage(stock.getNetPercentage(), 4));
//						}
//						else
//						// 量,額
//						{
//							// K/M/B
//							stock.setShareTraded(StringUtils.formatNumberByTurnove2(stock.getShareTraded(), 1));
//							stock.setTurnover(StringUtils.formatNumberByTurnove2(stock.getTurnover(), 1));
//						}
//						_top20List.add(stock);
//					}
//					catch (Exception e)
//					{
//						TDStockLog.d(TAG, "exception=Top20LoadDataAsyncTask > doInBackground >  foreach=" + e.toString());
//						e.printStackTrace();
//					}
//				}
//			}
//			else
//			{
//				SubcribeTop20();
//			}
//			return super.doInBackground(params);
//		}
//
//		@Override
//		protected void onPostExecute(Void result)
//		{
//			if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
//				_adapter.notifyDataSetChanged();
//			
//			super.onPostExecute(result);
//		}
//	}

	/*
	 * get data
	 */
	private void loadDataUpdateUI()
	{
//		new Top20LoadDataAsyncTask(getMyOwnContext()).execute();
		
		if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
		{
			SendHttpRequest();
		}
		else
		{
			SubcribeTop20();
		}
	}

	private void forwardToDestActivity(final int position)
	{
		if (position < 0 || _top20List.size() < position + 1)
		{
			return;
		}
		String itemCode = _top20List.get(position).getStockCode();
		if (TextUtils.isDigitsOnly(itemCode))
		{
			_prefs = getSharedPreferences(CommonDefn.SYSTEM_CURRENT_SETTING, Context.MODE_PRIVATE);
			_prefs.edit().putString(CommonDefn.PREFERENCE_STOCK_CODE, itemCode)
					.commit();
			
			Class<? extends ActivityGroup_Framework> stock_cls = CurrentStockInfoActivity.class;
			if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
			{
				stock_cls = BMPCurrentStockInfoActivity.class;
			}

			Intent intent = new Intent(getApplicationContext(), BMPCurrentStockInfoActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
			SwitchTabHostActivity(0, StockGroup.GetActivityGroupHostControl(), stock_cls, intent);
		}
	}

	@Override
	protected void onResume()
	{
		super.SetExectuHttpRequestOnResume(false);
		super.onResume();
		TDStockLog.d(TAG, TAG + " onResume");
		
		_isInBackground = false;
		
		if(tagName == null)
		{
			tagName = Top20Stock.TypeName_NetGainers;
			headerTitle = getResources().getString(R.string.top_20_stock_net);
		}
		else
		{
			String cameFrom = ((ITDLApplication) getApplicationContext()).getString(CommonDefn.ACTIVITY_CAME_FROM_KEY);
			if (cameFrom.contains(typeName_header))
			{
				tagName = cameFrom.replace(typeName_header, "");
				headerTitle = ((ITDLApplication) getApplicationContext()).getString(CommonDefn.TOP_BAR_TITLE);
			}
		}
		TDStockLog.i(TAG, "typeName=" + tagName);
		
		// reset header title
		resetHeaderTitle();
		resetTitle();

		// get data
		loadDataUpdateUI(); // get data update ui
		_listView.invalidateViews();		

	}

	@Override
	protected void onPause()
	{
		super.onPause();
		TDStockLog.d(TAG, TAG + " onPause");
		
		_isInBackground = true;
	}

	@Override
	protected void onStart()
	{
		super.onStart();
		TDStockLog.d(TAG, TAG + " onStart");
	}

	@Override
	protected void onRestart()
	{
		super.onRestart();
		TDStockLog.d(TAG, TAG + " onRestart");
	}

	@Override
	protected void onStop()
	{
		super.onStop();
		TDStockLog.d(TAG, TAG + " onStop");
	}

	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		TDStockLog.d(TAG, TAG + " onDestroy");
	}

	@Override
	public void onBackPressed()
	{
		// super.onBackPressed();
		TDStockLog.d(TAG, TAG + " onBackPressed");

		((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, "");
		Intent intent = new Intent(getApplicationContext(), MoreActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
		SwitchTabHostActivity(4, MoreGroup.GetActivityGroupHostControl(), MoreActivity.class, intent);
	}

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return MoreGroup.GetActivityGroupHostControl();
	}

	// 非 BMP Mode Top20
	
	protected void SubcribeTop20()
	{
		LS_SubscriptionItem interestItem = new LS_SubscriptionItem(Top20StockInfo.ADAPTER);
		
		interestItem.AddSubscribeItem(tagName);
		
		for(String field : Top20StockInfo.ITEM_FIELDS.get(tagName))
		{
			interestItem.AddSubscribeSchema(field);
		}
		LightStreamerSubscribeItem(LSGetUniqueID(), interestItem, this);
	}
	
	public void OnUpdateTop20(final int itemPos, final String itemName, final UpdateInfo update)
	{
		 if (_isInBackground)
		 {
			 return;
		 }
		 try
		 {
			 final Runnable runnable = new Runnable()
			 {
				@Override
				public void run()
				{
					 _top20List.clear();
					for (int index = 0; index < Top20StockInfo.RECORD_TOTAL_NUMBER; index++)
					{
						String stockCode = update.getNewValue(Top20StockInfo.STOCK + (index + 1));
						final String[] fields = new String[4];
						fields[0] = update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER + index));
						fields[1] = StringUtils.FormatNumber(
								StringUtils.ITDLNumber.STOCKPRICE,
								update.getNewValue(Top20StockInfo.getFieldName(
										itemName,
										Top20StockInfo.RECORD_TOTAL_NUMBER * 2
												+ index)));
						if (fields[1].indexOf(".") >= 5)
						{
							fields[1] = StringUtils.roundDownInteger(fields[1]);
						}
						else
						{
							fields[1] = StringUtils.roundDownFormatToFiveCharsRule(fields[1]);
						}
						
						Top20Stock stock = new Top20Stock();
						stock.setStockCode(stockCode);
						stock.setSchiName(fields[0]);
						stock.setNominal(fields[1]);
						
						if (itemName.equals(Top20StockInfo.ITEMS[0]) || itemName.equals(Top20StockInfo.ITEMS[4]))
						{
							// % 增
							// fields[2] = /*StringUtils.FormatNumber(StringUtils.ITDLNumber.NET, */
							// update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index));//);
							// fields[3] = /*String.format("%s", StringUtils.FormatNumber(StringUtils.ITDLNumber.NETPERCENTAGE,*/
							// update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index));//));
			
							fields[2] = StringUtils.formatNumberByNet(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
							fields[3] = StringUtils.formatNumberByNetPerectage(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)), 5);
//							TDStockLog.d(TAG, "tmp01=" + fields[0] + " , " + fields[1] + " , " + fields[2] + " , " + fields[3]);
							
							stock.setNet(fields[2]);
							stock.setNetPercentage(fields[3]);
						}
						else if (itemName.equals(Top20StockInfo.ITEMS[1]) || itemName.equals(Top20StockInfo.ITEMS[5]))
						{
							// % 减
							fields[2] = StringUtils.formatNumberByNet(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
							fields[3] = StringUtils.formatNumberByNetPerectage(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)), 4);
//							TDStockLog.d(TAG, "tmp02=" + fields[0] + " , " + fields[1] + " , " + fields[2] + " , " + fields[3]);
							
							stock.setNet(fields[2]);
							stock.setNetPercentage(fields[3]);
						}
						else
						{
							// K/M/B
							// fields[2] = StringUtils.FormatNumberOnTurnOverOrShareTraded(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
							// fields[3] = StringUtils.FormatNumberOnTurnOverOrShareTraded(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)));
							fields[2] = StringUtils.formatNumberByTurnove(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)), 1);
							fields[3] = StringUtils.formatNumberByTurnove(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)), 1);
//							TDStockLog.d(TAG, "tmp03=" + fields[0] + " , " + fields[1] + " , " + fields[2] + " , " + fields[3]);
							
							stock.setShareTraded(fields[2]);
							stock.setTurnover(fields[3]);
						}
						_top20List.add(stock);
					}
					_adapter.notifyDataSetChanged();
				}
			 };
			 new Thread()
			 {
				 @Override
				 public void run()
				 {
					 _messageHandler.post(runnable);
				 }
			 }.start();
			 
		 }
		 catch(Exception e)
		 {
			 e.printStackTrace();
		 }
	}

	@Override
	public void onUpdate(String iIdentifier, int iSchemaIndex, String iSchemaValue, UpdateInfo iUpdateInfo)
	{
		TDStockLog.d(TAG, "typeName="+iIdentifier+","+iSchemaIndex+","+iSchemaValue+","+iUpdateInfo.getItemName());
		OnUpdateTop20(iSchemaIndex, iSchemaValue, iUpdateInfo);
	}

	@Override
	public void ReporterTicker_Response(int iRemainSecond)
	{
	}
	
	@Override
	public void LS_UserClient_ConnectionReport(CONNECTION_STATUS iStatus)
	{
		TDStockLog.d(TAG, iStatus.name());
		super.LS_UserClient_ConnectionReport(iStatus);
		
		if(iStatus == CONNECTION_STATUS.CONNECTED)
		{
			if(!appHost.LSClient_IsConnected())
			{
				LightStreamerUnsubscribeAll();
				SubcribeTop20();
			}
		}
		else
		{
//			TryToLogon(true);
			HttpAppInfo.SendFrameworkReLogonRequest(null);
		}
	}
	
	private void clearBMPData()
	{
		if(_top20List.size() > 0)
		{
			_top20List.clear();
			_adapter.notifyDataSetChanged();
		}
	}

	@Override
	protected H_CODE GetDataFromHttpServer()
	{
		clearBMPData();
		return HttpAppInfo.SendBMPTop20Request(actContext, tagName, isNet, this);
	}

	@Override
	protected void H_UserClient_HttpRequest_Response_Sub(H_UserClient_HttpRequest_Result iResult)
	{
		if(!iResult.MStatus.equals("0"))
		{
			ShowMessageDialog(iResult.MError + "(" + iResult.MStatus + ")");
			return;
		}
		
		final List<Top20Stock> iTop20List = (List<Top20Stock>)iResult.objListStores;
		
		Runnable runnable = new Runnable()
		{
			@Override
			public void run()
			{
				updateBMPData(iTop20List);
			}
		};
		_messageHandler.post(runnable);
	}
	
	private void updateBMPData(List<Top20Stock> list)
	{
		String name = tagName;
		
		for (Top20Stock stock : list)
		{
			try
			{
				// 現價
				String nominal = stock.getNominal();
				if (nominal.indexOf(".") >= 5)
				{
					nominal = StringUtils.roundDownInteger(nominal);
				}
				else
				{
					nominal = StringUtils.roundDownFormatToFiveCharsRule(nominal);
				}
				stock.setNominal(nominal);

				// 升跌$,升跌%,成交量,成交額
				if (name.contains(Top20Stock.TypeName_NetGainers)) // 升
				{
					stock.setNet(StringUtils.formatNumberByNet(stock.getNet()));
					stock.setNetPercentage(StringUtils.formatNumberByNetPerectage(stock.getNetPercentage(), 5));
				}
				else if (name.contains(Top20Stock.TypeName_NetLosers)) // 跌
				{
					stock.setNet(StringUtils.formatNumberByNet(stock.getNet()));
					stock.setNetPercentage(StringUtils.formatNumberByNetPerectage(stock.getNetPercentage(), 4));
				}
				else
				// 量,額
				{
					// K/M/B
					stock.setShareTraded(StringUtils.formatNumberByTurnove2(stock.getShareTraded(), 1));
					stock.setTurnover(StringUtils.formatNumberByTurnove2(stock.getTurnover(), 1));
				}
				_top20List.add(stock);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		
		_adapter.notifyDataSetChanged();
	}
}
